<?php
/**
 * 函数自动加载
 * 
 * @author  chenjainwei
 */

class AutoLoad {
	
	public function __construct() {
	
	}
	
	final private function _loadClass($classname) {
		if (! file_exists ( CACHE_DIR . "class_map.cfg.php" )) {
			require_once 'batch/LoadClass.php';
			$loadfile = new LoadClass ( );
		}
		require_once 'cache/class_map.cfg.php';
		$cls = new ClassMap ( );
		$classMap = $cls->getArray ();
		return $classMap;
	}
	/**
	 * load class
	 *
	 * @param  $class
	 */
	final static public function autoload($class) {
		$classMap = self::_loadClass ( $class );
		if (array_key_exists ( $class, $classMap )) {
			include_once $classMap [$class];
		}
	}
	/**
	 * register class
	 *
	 * @param unknown_type $class
	 * @param unknown_type $enabled
	 */
	
	final static public function registerAutoload($class = 'AutoLoad', $enabled = true) {
		if (! function_exists ( 'spl_autoload_register' )) {
			exit ( "spl_autoload在该PHP版本中没有安装" );
		}
		spl_autoload_register ( array ($class, 'autoload' ) );
	}

}

?>